package cn.echo.modules.sys.service;





import cn.echo.modules.sys.dao.LinkMapper;
import cn.echo.modules.sys.entity.Link;
import cn.echo.modules.sys.utils.MyBatisUtils;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * Created by Administrator on 2017/4/14.
 */

@Service("linkSerivce")
public class LinkService {

    public List<Link> findAll(Link link){
       SqlSession session= MyBatisUtils.getSqlFactory().openSession(true);
        LinkMapper linkMapper = session.getMapper(LinkMapper.class);
        List<Link> linkList = linkMapper.findAll(new Link());
        session.close();
        return linkList;
    }
    public boolean insert(Link link){
        boolean flag = false;
        SqlSession session = null;
        session = MyBatisUtils.getSqlFactory().openSession(true);
        LinkMapper linkMapper = session.getMapper(LinkMapper.class);
        boolean b = linkMapper.insert(link);
        flag = b;
        session.close();
        return flag;
    }
    public boolean update(Link link){
        boolean flag = false;
        SqlSession session=null;
        session = MyBatisUtils.getSqlFactory().openSession(true);
        LinkMapper linkMapper = session.getMapper(LinkMapper.class);
        boolean b = linkMapper.updateByid2(link);
        flag = b;
        session.close();
        return flag;
    }

    public boolean deleteByid(Link link){
        boolean flag = false;
        SqlSession session = null;
        session = MyBatisUtils.getSqlFactory().openSession(true);
        LinkMapper linkMapper = session.getMapper(LinkMapper.class);
        boolean b = linkMapper.deleteByFlag(link);
        flag = b;
        session.close();
        return flag;
    }
    public List<Link> selectAll(){
        boolean flag = false;
        SqlSession session = null;
        session = MyBatisUtils.getSqlFactory().openSession(true);
        LinkMapper linkMapper = session.getMapper(LinkMapper.class);
        List<Link> links = linkMapper.selectAll();
        for (Link k:links) {
            System.out.println(k);
        }
        return links;
    }
}
